package es.app.services;

import java.io.Serializable;
import java.util.List;

import es.app.services.interfaces.IService;
import es.app.util.GenericDAO;

public abstract class ServicioGenerico<T extends Serializable, K> implements IService<T, K>{
	
	protected GenericDAO<T, K> dao;
	
	public List<T> findAll() throws RuntimeException{
		try {
			List<T> lista = dao.findAll();
			return lista;
		} catch (Exception e) {
			return null;
		}

	}

	public K crear(T object) throws RuntimeException{
		try {
			return dao.create(object);
		} catch (Exception e) {
			return null;
		}
	}

	public void update(T object) throws RuntimeException{
		try {
			dao.update(object);
		} catch (Exception e) {

		}
	}
	
	public T find(K key)throws RuntimeException{
		try {
			return dao.findById(key);
		} catch (Exception e) {
			return null;
		}
		
	}

	public GenericDAO<T, K> getDao() {
		return dao;
	}

	public void setDao(GenericDAO<T, K> dao) {
		this.dao = dao;
	}
}
